import xmlrpclib
import xmlrpclib
import traceback

g_rpc_port = 22223

def getHostData(url):
    ret = {'code': -1, 'data': ''} 
    try:
        ip = url.replace('host://', '') 
        link = "http://%s:%d" % (ip, g_rpc_port)
        print link
        server = xmlrpclib.ServerProxy(link)
        info = server.host.get_info()
        #del server
        cpu = "%.3f" % info['cpu_usage'] 
        mem = "%.3f" % (info['mem_usage'] * info['mem_total'])
        disk = "1" 
        load = "1" 
        network = "1" 
        ret['data'] = "cpu:%s,mem:%s,disk:%s,load:%s,network:%s" % (cpu, mem, disk, load, network)
        return ret 
    except:
        traceback.print_exc()
        return ret


print getHostData("host://127.0.0.1")
